package com.bw.controller;

import com.alibaba.fastjson.JSONObject;
import com.bw.pojo.vo.PurchaseVo;
import com.bw.service.impl.PurchaseGoodsServiceImpl;
import com.bw.util.JDBCUtil;
import com.bw.util.PageResult;
import com.github.pagehelper.PageInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/purchase/*")
public class PurchaseController extends BaseController{
    PurchaseGoodsServiceImpl service = new PurchaseGoodsServiceImpl();
    protected void getPurchaseList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String reqInfos = req.getParameter("reqInfos");
        PurchaseVo purchaseVo = JSONObject.parseObject(reqInfos, PurchaseVo.class);
        PageInfo<PurchaseVo> pageInfo = service.getPurchaseList(purchaseVo);
        resp.getWriter().println(JSONObject.toJSONString(pageInfo));
    }
    protected void addPurchase(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String reqInfos = req.getParameter("reqInfos");
        PurchaseVo purchaseVo = JSONObject.parseObject(reqInfos, PurchaseVo.class);
        service.addPurchase(purchaseVo);
        resp.getWriter().println(JSONObject.toJSONString(200));
    }
}
